package top.fengyulou.xiaofeng.common;

import java.util.ArrayList;
import java.util.List;

/**
 * @author guochao
 * @version 1.0
 * @date 2022/4/16 20:16
 */
public class CommonUtils {
    /**
     * id串转Long类型集合
     *
     * @param ids
     * @return
     * @author guochao
     */
    public static List<Long> idsToLongList(String ids) {
        String[] split = ids.split(",");
        List<Long> list = new ArrayList<>();
        for (String id : split) {
            if (!list.contains(id)) {
                list.add(Long.parseLong(id));
            }
        }
        return list;
    }

    /**
     * id串转String类型集合
     *
     * @param ids
     * @return
     * @author guochao
     */
    public static List<String> idsToStrList(String ids) {
        String[] split = ids.split(",");
        List<String> list = new ArrayList<>();
        for (String id : split) {
            if (!list.contains(id)) {
                list.add(id);
            }
        }
        return list;
    }

    /**
     * tab键缩进
     *
     * @param num
     * @return
     */
    public static String tabIndent(int num) {
        StringBuilder stringBuilder = new StringBuilder();
        String blank = "    ";
        for (int i = 0; i < num; i++) {
            stringBuilder.append(blank);
        }
        return stringBuilder.toString();
    }
}
